 #include <iostream>
#include <string>
#include <cmath>

using namespace std;

bool isPrime(int n) {
    if (n <= 1)
        return false;
    for (int i = 2; i <= sqrt(n); ++i) {
        if (n % i == 0)
            return false;
    }
    return true;
}

int main() {
    string words[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"};
    string input;
    getline(cin, input);

    int num = 0;
    int count = 0;
    string temp = "";
    for (char c : input) {
        if (c == ' ') {
            for (int i = 0; i < 10; ++i) {
                if (temp == words[i]) {
                    num = num * 10 + i;
                    ++count;
                    break;
                }
            }
            temp = "";
        } else {
            temp += c;
        }
    }
    for (int i = 0; i < 10; ++i) {
        if (temp == words[i]) {
            num = num * 10 + i;
            ++count;
            break;
        }
    }

    if (count != 3) {
        cout << "Wrong input" << endl;
    } else {
        if (isPrime(num)) {
            cout << num << endl;
        } else {
            int lower = num;
            int upper = num;
            while (!isPrime(lower) || !isPrime(upper)) {
                ++upper;
                if (lower > 0)
                    --lower;
            }
            cout << (upper - num >= num - lower ? lower : upper) << endl;
        }
    }

    return 0;
}
